/*************************************************************************
	> File Name: b-u.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: 2014年06月15日 星期日 20时03分52秒
 ************************************************************************/

#include<stdio.h>
#include<unistd.h>
#include<signal.h>
int main(int argc, char *argv[])
{
    sigset_t unblock;

    sigset_t set;

    if(sigfillset(&set)==-1)
    {
        perror("sigfillset:");
        raise(2);
    }
    
    if(sigprocmask(SIG_BLOCK,&set,NULL)==-1)
    {
        perror("sigprocmask:");
        raise(2);
    }

    printf("\e[42m Now all signal has been blocked\e[0m\n");
    sleep(10);

/*    if(sigemptyset(&unblock)==-1)
    {
        perror("sigemptyset:");
        raise(2);
    }
    this function only needed when use SIG_SETMASK
    */

    printf("May be you can kill this proccess now\n"); // it turn out that process cannot be terminate at this time
    sleep(10);

    if(sigprocmask(SIG_UNBLOCK,&set,NULL)==-1) // this way is directly unblock the blocked signal to make proccess can be killed
    {
        perror("sigprocmask_2:");
        raise(2);
    }
    /*if(sigprocmask(SIG_SETMASK,&unblock,NULL)==-1) // this way is along with the if(sigemptyset(&unblock))==-1) this function then use sigprocmask SIG_SETMASK point to &unblock , and the unblock contented nothing so proccess can be killed
    {
        perror("sigprocmask_2:");
        raise(2);
    }*/
    printf("\e[33m if you failed then you can try again\e[0m\n"); // only if the above if sentance has run then the proccess can be killed by some sig 
    sleep(10);
    _exit(0);
}
